package com.gxan.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gxan.common.R;
import com.gxan.service.RecruitmentService;
import com.gxan.service.impl.RecruitmentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet({"/recruitment/delRecruitment","/recruitment/delRecruitments"})
public class DelRecruitmentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        R<Object> r = new R<>();
        //获取前端传递过来的参数
        String ids[] = request.getParameterValues("ids");
        String satff_id = request.getParameter("id");
        //交给service处理
        RecruitmentService recruitmentService = new RecruitmentServiceImpl();
        if(satff_id==null){
            //多条删除
             r = recruitmentService.delRecruitmentById(ids);
        }else{
            //单条删除
            String idss[] ={satff_id};
             r = recruitmentService.delRecruitmentById(idss);
        }

        //返回数据到前端
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        response.getWriter().write(JSONObject.toJSONString(r));
        response.getWriter().flush();
        response.getWriter().close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
